//
// Created by Ivor_ on 2022/3/12.
//

#ifndef PHYSICAL_COMPUTING_PACKAGE_INTERPOLATION_H
#define PHYSICAL_COMPUTING_PACKAGE_INTERPOLATION_H

#include <math.h>
#include <stdlib.h>

#include "../vectorAndMatrix/matrixOperate.h"

/**
 * @author Ivor
 * @param points known points for x(points[i][0]) and y(points[i][1]) (and y'(points[i][2]) for hermiteIp), disordered is accepted
 * @param numOfPoints how many i, for example, i = 0,1,2,...,n-1, numOfPoints = n
 * @param objPoints for many objective points, only call once function
 * @param numOfObjPoints just as its name
 * @return return value's the [i]th value is just for the objPoints[i]'s interpolation result
 * @remark lagrangeIp and newtonIp is for ordinary polynomial interpolation, hermiteIp donsidered the slope, and sectionIp is the form of polyline which is to avoid the Runge effect
 */
double* lagrangeIp(double** points, int numOfPoints, double* objPoints, int numOfObjPoints);
double* newtonIp(double** points, int numOfPoints, double* objPoints, int numOfObjPoints);
double* hermiteIp(double** points, int numOfPoints, double* objPoints, int numOfObjPoints);
double* sectionIp(double** points, int numOfPoints, double* objPoints, int numOfObjPoints);

/**
 * @author Ivor
 * @param points known points for x(points[i][0]) and y(points[i][1]), ascending by x(points[i][0]) is required
 * @param numOfPoints how many i, for example, i = 0,1,2,...,n-1, numOfPoints = n
 * @param method 'm' or 'M', 'm' for first-ordered derivative method, 'M' for second-ordered derivative method
 * @param boundary 'm' or 'M', 'm' for first-ordered derivative boundary condition, 'M' for second-ordered derivative boundary condition
 * @param bs m[0] or M[0]
 * @param be m[n-1] or M[n-1]
 * @param objPoints for many objective points, only call once function
 * @param numOfObjPoints just as its name
 * @return return value's the [i]th value is just for the objPoints[i]'s interpolation result
 * @remark based on the section interpolation method, and the interpolation function satisfy first-order smoothness, just as the spline. Each section is the cubic polynome.
 */
double* cubicSplineIp(double** points, int numOfPoints, char method, char boundary, double bs, double be, double* objPoints, int numOfObjPoints);

#endif //PHYSICAL_COMPUTING_PACKAGE_INTERPOLATION_H
